using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TradeFlow.Server.Service;
using System.Threading.Tasks;

namespace TradeFlow.Web.Controllers
{
    /// <summary>
    /// 通用功能控制器
    /// </summary>
    [Authorize]
    public class JxCommonController : Controller
    {
        private readonly JxCommonService _commonService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="commonService"></param>
        public JxCommonController(JxCommonService commonService)
        {
            _commonService = commonService;
        }

        ///// <summary>
        ///// 检查商品编码是否重复
        ///// </summary>
        ///// <param name="code">商品编码</param>
        ///// <param name="id">排除的商品ID</param>
        ///// <returns></returns>
        //[HttpGet]
        //public async Task<IActionResult> ExistsGoodsCode(string code, string id = null)
        //{
        //    var exists = await _commonService.ExistsGoodsCodeAsync(code, id);
        //    return Json(new { exists });
        //}

        ///// <summary>
        ///// 检查商业伙伴名称是否重复
        ///// </summary>
        ///// <param name="name">商业伙伴名称</param>
        ///// <param name="id">排除的ID</param>
        ///// <returns></returns>
        //[HttpGet]
        //public async Task<IActionResult> ExistsPartnerName(string name, string id = null)
        //{
        //    var exists = await _commonService.ExistsPartnerNameAsync(name, id);
        //    return Json(new { exists });
        //}

        /// <summary>
        /// 获取最大业务单号
        /// </summary>
        /// <param name="billType">单据类型</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetMaxBillNo(string billType)
        {
            var maxBillNo = await _commonService.GetMaxBillNoAsync(billType);
            return Json(new { billNo = maxBillNo });
        }

        ///// <summary>
        ///// 获取最大对账单号
        ///// </summary>
        ///// <returns></returns>
        //[HttpGet]
        //public async Task<IActionResult> GetMaxAccountNo()
        //{
        //    var maxAccountNo = await _commonService.GetMaxAccountNoAsync();
        //    return Json(new { accountNo = maxAccountNo });
        //}
    }
}